package com.controller.lyxmcontroller.controller.detail;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.service.lyxmserviceapi.model.ArticleModel;
import com.service.lyxmserviceapi.model.Module;
import com.service.lyxmserviceapi.service.ArticleDetailService;
import com.service.lyxmserviceapi.service.index.IndexService;
import com.service.lyxmserviceapi.service.module.ModuleService;

@Controller
public class ArticleDetailController {
	
	@Autowired
	private ArticleDetailService articleDetailServiceImpl;
	@Autowired
	private ModuleService moduleService;
	@Autowired
	private IndexService indexServiceImpl;
	@RequestMapping( value = "/getArticle/{articleId}",method = RequestMethod.GET)
	public String index(@PathVariable("articleId") String articleId,Model model,HttpServletResponse response,HttpServletRequest request){
		System.out.println("i REALLY am in");
		//String a = testService.iAmtest("","13");
		//System.out.println(a);
		//文章实体
		ArticleModel articleModel = articleDetailServiceImpl.getOneArticleModel(articleId);
		model.addAttribute("articleModel",articleModel);
		//获取首页模块列表
		List<Module> moduleList = indexServiceImpl.getIndexModule();
		model.addAttribute("moduleList",moduleList);
		//最近发布模块
		List<ArticleModel> newArticleModelList = articleDetailServiceImpl.getArticleModelListWithOutOneId(articleModel.getId().toString(), articleModel.getAuthor().getId().toString());
		model.addAttribute("newArticleModelList",newArticleModelList);
		
		
		System.out.println(articleModel.getContext());
		//sender.send();
		return "/articleDetail/atricleDetail";
	}
}
